/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.merak.core.configuration.plugin;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class PluginSet implements Iterable<Service> {

	//~ Attributes ///////////////////////////////////////////////////////////////
	//****************************************************************************
	private String              spiPackage = null;
	private Map<String,Service> services   = new HashMap<String,Service>();

	//~ Constructors /////////////////////////////////////////////////////////////
	//****************************************************************************
	//~ Methods //////////////////////////////////////////////////////////////////
	//****************************************************************************
	public String getSpiPackage() {
		return this.spiPackage;
	}
	//****************************************************************************
	public void setSpiPackage(String spiPackage) {
		this.spiPackage = spiPackage;
	}
	//****************************************************************************
	public void addService(Service service) {
		if ( service!=null && !this.services.containsKey(service.getName()) ) {
			this.services.put(service.getName(),service);
		}
	}
	//****************************************************************************
	public Service getService(String name) {
		return this.services.get(name);
	}
	//****************************************************************************
	@Override
	public Iterator<Service> iterator() {
		return this.services.values().iterator();
	}
	//****************************************************************************
	@Override
	public String toString() {

		String e = "["+this.spiPackage+"]";
		for (Service p : this.services.values()) {
			e+="\n"+p;
		}
		return e+"\n";

	}
	//****************************************************************************
}
